package com.pfzy.liveeventbusdemo.activity

import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import androidx.databinding.DataBindingUtil
import com.jeremyliao.liveeventbus.LiveEventBus
import com.pfzy.liveeventbusdemo.LiveEventBusDemo
import com.pfzy.liveeventbusdemo.R
import com.pfzy.liveeventbusdemo.databinding.ActivityObserverActiveLevelDemoBinding

/**
 * 观察者活动水平
 */
class ObserverActiveLevelActivity : AppCompatActivity() {
    private var binding: ActivityObserverActiveLevelDemoBinding? = null
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        binding = DataBindingUtil.setContentView(this, R.layout.activity_observer_active_level_demo)
        binding?.lifecycleOwner = this
        binding?.handler = this

        LiveEventBus.config(LiveEventBusDemo.KEY_TEST_ACTIVE_LEVEL_SINGLE)
            .lifecycleObserverAlwaysActive(false)
    }

    override fun onDestroy() {
        super.onDestroy()
    }

    fun sendMsgToPrevent() {
        LiveEventBus
            .get<String>(LiveEventBusDemo.KEY_TEST_ACTIVE_LEVEL)
            .post("Send Msg To Observer Stopped")
    }

    fun sendMsgToPreventSingle() {
        LiveEventBus
            .get<String>(LiveEventBusDemo.KEY_TEST_ACTIVE_LEVEL_SINGLE)
            .post("Send Msg To Observer Stopped")
    }
}